<?php
/**
 * @package PHPKit.
 * @author: mawenpei
 * @date: 2016/11/28
 * @time: 15:28
 */
namespace HuoKit\HuoServer\Adapter\Laravel;

use HuoKit\HuoServer\Adapter\IRequestHandler;
use swoole_http_request as SwooleHttpRequest;
use swoole_http_response as SwooleHttpResponse;

class RequestHandler implements IRequestHandler
{
    public function handle(SwooleHttpRequest $swooleRequest, SwooleHttpResponse $swooleResponse,$swooleServer)
    {
        $this->initGPC($swooleRequest, $swooleResponse,$swooleServer);
    }

    protected function initGPC($swooleRequest,$swooleResponse,$swooleServer)
    {
        $_GET = $_POST = $_COOKIE = $_SERVER = $_FILES = [];
        $GLOBALS['REQUEST'] = $swooleRequest;
        $GLOBALS['RESPONSE'] = $swooleResponse;
        $GLOBALS['SWOOLE_SERVER'] = $swooleServer;

        $_GET = $swooleRequest->get;

        if(isset($swooleRequest->post)){
            $_POST = $swooleRequest->post;
        }
        if(isset($swooleRequest->server)){
            $_SERVER = $swooleRequest->server;
        }
        if(isset($swooleRequest->cookie)){
            $_COOKIE = $swooleRequest->cookie;
        }
        if(isset($swooleRequest->files)){
            $_FILES = $swooleRequest->files;
        }
    }
}